<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <script src="https://cdn.bootcdn.net/ajax/libs/react/16.8.4/umd/react.development.js"></script>
    <script src="https://cdn.bootcdn.net/ajax/libs/react-dom/16.8.4/umd/react-dom.development.js"></script>
    <script src="https://unpkg.com/@babel/standalone/babel.min.js"></script>
    <script src="https://cdn.bootcdn.net/ajax/libs/prop-types/15.8.1/prop-types.js"></script>
  </head>
  <body>
    <div id="test"></div>
    <script type="text/babel">
      class Person extends React.Component {
        // 类型限制
        static propTypes = {
          name: PropTypes.string,
          age: PropTypes.number.isRequired,
        };
        static defaultProps = {
          name: "zhangsan",
        };
        // constructor(props) {}
        render() {
          console.log("19", this);
          // props中的属性时只读的，不能直接修改
          // this.props.name = "hello";
          return (
            <div>
              <ul>
                <li>姓名:{this.props.name}</li>
                <li>性别:{this.props.age + 2}</li>
              </ul>
            </div>
          );
        }
      }

      let info = {
        name: "liudehua",
        age: 20,
      };
      ReactDOM.render(<Person {...info} />, document.getElementById("test"));
    </script>
  </body>
</html>
